/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.ivanbiz.helper;

import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.nio.charset.Charset;
import java.util.PropertyResourceBundle;
import java.util.ResourceBundle;
import java.util.logging.Level;
import java.util.logging.Logger;

/**
 *
 * @author Ivan
 */
public class ReadConfig {

    String key;
    public ResourceBundle rb;
    public File file = null;
    public String str;
    InputStream inputStream = null;
    OutputStream outputStream = null;

    public ReadConfig() {
        try {
            file = new File("config.properties");
            FileInputStream fis = new FileInputStream(file.getAbsolutePath());
            InputStreamReader reader = new InputStreamReader(fis, Charset.forName("UTF-8"));
            rb = new PropertyResourceBundle(reader);
            str = file.getAbsolutePath().substring(0, file.getAbsolutePath().indexOf("config.properties"));
        } catch (IOException ex) {
            Logger.getLogger(ReadConfig.class.getName()).log(Level.SEVERE, null, ex);
        }
    }

    public void copyFile(String source, String destination) {
        File fileSource = new File(source);
        File fileDestination = new File(destination);
        try {
            inputStream = new FileInputStream(fileSource);
            outputStream = new FileOutputStream(fileDestination);
            byte[] buffer = new byte[1024];
            int legth;
            // copy file content in byte
            while ((legth = inputStream.read(buffer)) > 0) {
                outputStream.write(buffer, 0, legth);
            }
            inputStream.close();
            outputStream.close();
            // delete the original file
            // cfile.delete();
        } catch (FileNotFoundException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        }
    }

    public static void main(String[] args) {
        //System.out.println(System.getProperty("user.dir") + "\\image\\");
    }
}
